package com.suitsoft.ut.dao.commons;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springside.modules.orm.Page;

import com.suitsoft.ut.util.StringUtils;

/**
 *
 *@author Suine
 */
@Repository
public class ExpDao {
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public void find(Page<Map<String,Object>> page,String colloge,String zhuanye,String studentNo,String studentName,String teacherName,String teacherNos){
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT T.ID, T.TITILE,T.TEACHER_NAME,T.TEACHER_POST,T.STUDENT_NAME,T.STUDENT_NO ");
		sb.append(" FROM LW_THESIS T,LW_THESIS_FILE TF,BD_STUDENT ST,BD_TEACHER TC,LW_COLLEGE C,LW_DISCIPLINE D ");
		sb.append(" WHERE T.STUDENT_NO = ST.STUDENT_NO	 AND ST.DISCIPLINE_ID = D.ID AND T.ID = TF.THESIS_ID AND T.TEACHER_NO = TC.TEACHER_NO AND D.COLLEGE_ID = C.ID ");
		if(!StringUtils.isEmpty(colloge)){
			sb.append(" AND C.COLLEGE_NAME LIKE '%"+colloge+"%' ");
		}
		if(!StringUtils.isEmpty(zhuanye)){
			sb.append(" AND D.DISCIPLINE_NAME LIKE '%"+zhuanye+"%' ");
		}
		if(!StringUtils.isEmpty(studentName)){
			sb.append(" AND T.STUDENT_NAME LIKE '%"+studentName+"%' ");
		}
		if(!StringUtils.isEmpty(studentNo)){
			sb.append("AND T.STUDENT_NO LIKE '"+studentNo+"%' ");
		}
		if(!StringUtils.isEmpty(teacherNos)){
			sb.append(" AND T.TEACHER_NAME LIKE '%"+teacherNos+"%' ");
		}
		if(!StringUtils.isEmpty(teacherName)){
			sb.append(" AND T.TEACHER_NO LIKE '"+teacherName+"%' ");
		}
		sb.append(" order by t.id");
		jdbcTemplate.queryForPage(page, sb.toString());
	}

}

